package com.weayer.service;

import com.weayer.constant.CommonStatusEnum;
import com.weayer.dto.ResponseResult;
import com.weayer.remote.MapDirectionClient;
import com.weayer.response.DirectionResponse;
import com.weayer.response.ForecastPriceResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * @description: 地图Service
 * @author: Weayer
 **/
@Service
public class DirectionService {

    @Autowired
    MapDirectionClient mapDirectionClient;

    /**
     * @Description: 根据经纬度数据，调用api获取距离（米）和时长（秒）
     * @Param: [depLongitude, depLatitude, desLongitude, desLatitude]
     * @return: com.weayer.dto.ResponseResult
     **/
    public ResponseResult driving(String depLongitude, String depLatitude, String desLongitude, String desLatitude){
        // 调用地图服务，查询距离和时长
        DirectionResponse directionResponse = mapDirectionClient.direction(depLongitude, depLatitude, desLongitude, desLatitude);
        return directionResponse == null ?
                ResponseResult.fail(CommonStatusEnum.MAP_ERROR.getCode(), CommonStatusEnum.MAP_ERROR.getValue()) :
                ResponseResult.success(directionResponse);
    }
}
